import Opt from '@/components/dt/info/Opt.js'
import billMgr from '@/biz/bonus/bill'
import specialMgr from '@/biz/bonus/billSpecial'
import dateOpt from '@/biz/option/date.js'
import tool from '@/common/tool'

class RoomColumn extends Opt {

  constructor(name, bonusId, update) {
    super()
    this.bonusId = bonusId
    this.name = name
    this.update = update
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
      type: 'index',
      fixed: 'left',
      title: '序号',
      minWidth: 50,
    },
    {
      field: 'productName',
      fixed: 'left',
      title: '产品名称',
      minWidth: 130,
    },
    {
      field: 'roomName',
      fixed: 'left',
      title: '房源名称',
      minWidth: 130,
      // header: {
      //   filter: {
      //     title: '房源名称',
      //     key: 'roomName',
      //     placeholder: '请输入房源名称',
      //     input: {},
      //   },
      // },
    },
    {
      field: 'customerName',
      title: '客户姓名',
      minWidth: 110,
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    },
    {
      field: 'contractDate',
      title: '签约日期',
      minWidth: 120,
      header: {
        filter: dateOpt.range({
          title: '签约日期',
          startKey: 'contractStartDate',
          endKey: 'contractEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (tool.dateDiff(val.contractStartDate, val
                .contractEndDate).Y >= 2) {
              // 日期最大跨度两年
              Message.warning('认购日期跨度至多两年。')
            }
            return !(tool.dateDiff(val.contractStartDate, val
              .contractEndDate).Y >= 2)
          }
        }),
      },
      cell: {
        text: {
          type: 'date'
        }
      }
    },
    {
      field: 'predictAccountDate',
      title: '全款到账日期',
      minWidth: 140,
      header: {
        filter: dateOpt.range({
          title: '全款到账日期',
          startKey: 'accountDateStart',
          endKey: 'accountDateEnd',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (tool.dateDiff(val.accountDateStart, val
                .accountDateEnd).Y >= 2) {
              // 日期最大跨度两年
              Message.warning('全款到账日期跨度至多两年。')
            }
            return !(tool.dateDiff(val.accountDateStart, val
              .accountDateEnd).Y >= 2)
          }
        }),
      },
      cell: {
        text: {
          type: 'date'
        }
      }
    },
    {
      field: 'workNo',
      title: '工号',
      minWidth: 90,
    },
    {
      field: 'userName',
      title: '姓名',
      minWidth: 90,
      header: {
        filter: {
          title: '姓名',
          key: 'userName',
          placeholder: '请输入姓名',
          input: {},
        },
      }
    },
    {
      field: 'postName',
      title: '岗位',
      minWidth: 90,
    },
    {
      field: 'rankName',
      title: '职级',
      minWidth: 90,
    },
    {
      field: 'shouldBonusAmount',
      title: '应付奖金(元)',
      minWidth: 150,
      cell: (info) => {
        if (this.name == 'billEdit') {
          return {
            edit: {
              input: {
                type: 'number',
                blur: () => {
                  specialMgr.roomEdit(info.bonusDetailId, info.shouldBonusAmount)
                    .finally(res => {
                      this.update()
                    })
                }
              }
            }
          }
        } else {
          return {
            text: {
              type: 'number'
            }
          }
        }
      }
    },
    {
      field: 'bonusPool',
      title: '计提奖金池(元)',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'actualBonusAmount',
      title: '实发奖金(元)',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '操作',
      fixed: 'right',
      width: 110,
      visible: this.name == 'billEdit',
      cell: {
        btn: {
          title: '删除',
          event: 'onDelete',
        }
      }
    }]
  }
}

export default RoomColumn